using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Net.Mail;
/// <summary>
/// Summary description for MKData
/// version 1.2
/// date changed: 05 Aug 2010
/// </summary>
 public  class MKCommon
{
     public MKCommon()
	{
		//
		// TODO: Add constructor logic here
		//
	}
     
     public static string toDate(string dt) {
         if (dt!="" && isDate(dt) )
         {
             return string.Format("{0:dd MMM yyyy}", System.Convert.ToDateTime(dt));
         }
         else
             return "False";
     }
     public static string toDateTime(string dt)
     {
         if (dt != "" && isDate(dt))
         {
             return string.Format("{0:dd-MM-yyyy HH:mm}", System.Convert.ToDateTime(dt));
         }
         else
             return "";
     }

     public static bool toChecked(string chk)
     {
         try
         {
             if (chk == "1" || chk == "true" || chk == "True")
             {
                 return true;
             }
             else
                 return false;
         }
         catch { return false; }
     }
     public static bool toChecked(int chk)
     {
         if (chk == 1)
         {
             return true;
         }
         else
             return false;
     }
     public static string BoolToNumStr(string value)
     {
         if (value == "1" || value == "true" || value == "True")
         {
             return "1";
         }
         else
             return "0";
     }
     private static bool isDate(string inValue){

        try {
            DateTime myDT = System.Convert.ToDateTime(inValue);
            return true;
        }
        catch (FormatException e) {
            return  false;
        }
    }
     
     public static bool IsNumeric(string s)
     {
         try {  Int32.Parse(s);   }
         catch  {    return false; }
         return true;
     }
     
     //public static DropDownList selectDropDownByValue(DropDownList ddlMyDropDown, String value){
     //    try
     //    {
     //        ddlMyDropDown.Items.FindByValue(value).Selected = true;
     //        return ddlMyDropDown;
     //    }
     //    catch {
     //        ddlMyDropDown.Items[0].Selected = true;
     //        return ddlMyDropDown;
     //    }
     //}
     //public static DropDownList selectDropDownByText(DropDownList ddlMyDropDown, String value)
     //{
     //    try
     //    {
     //        ddlMyDropDown.Items.FindByText(value).Selected = true;
     //        return ddlMyDropDown;
     //    }
     //    catch
     //    {
     //        ddlMyDropDown.Items[0].Selected = true;
     //        return ddlMyDropDown;
     //    }
     //}
     //public static RadioButtonList selectRadioByValue(RadioButtonList rdMyRadio, String value)
     //{
     //    try
     //    {

     //        rdMyRadio.Items.FindByValue(value).Selected = true;
     //        return rdMyRadio;
     //    }
     //    catch
     //    {
     //        return rdMyRadio;
     //    }
     //}

     public static string Left(string param, int length)
     {
         //we start at 0 since we want to get the characters starting from the
         //left and with the specified lenght and assign it to a variable
         string result = param.Substring(0, length);
         //return the result of the operation
         return result;
     }
     public static string Right(string param, int length)
     {
         //start at the index based on the lenght of the sting minus
         //the specified lenght and assign it a variable
         string result = param.Substring(param.Length - length, length);
         //return the result of the operation
         return result;
     }

     public static string Mid(string param, int startIndex, int length)
     {
         //start at the specified index in the string ang get N number of
         //characters depending on the lenght and assign it to a variable
         string result = param.Substring(startIndex, length);
         //return the result of the operation
         return result;
     }

     public static string Mid(string param, int startIndex)
     {
         //start at the specified index and return all characters after it
         //and assign it to a variable
         string result = param.Substring(startIndex);
         //return the result of the operation
         return result;
     }
  
     public static bool EmailSend(string to, string from, string subject, string body, bool IsBodyHtml)
     {
         MailMessage mm = new MailMessage(from,to);
         mm.Subject = subject;
         mm.Body = body;
         if (IsBodyHtml)
            mm.IsBodyHtml =  true;
         SmtpClient smtp = new SmtpClient();
         try { smtp.Send(mm); return true; }
         catch (Exception exp) { return false; }
     }
   

 } //end class
